package tp.pr1;

public class Street {
	/**
	 * 
	 * @param source Inicio de la calle
	 * @param direction Dirección de la calle
	 * @param target Destino de la calle
	 */
	public Street (Place source, Direction direction, Place target){
		this.source = source;
		this.direction = direction;
		this.target = target;
	}
	/**
	 * 
	 * @param place
	 * @param whichDirection
	 * @return Returns true if the street comes out from the input Place.
	 */
	public boolean comeOutFrom (Place place, Direction whichDirection){
		return (this.source.equals(place) && this.direction.equals(whichDirection) || this.target.equals(place) && this.direction.equals(whichDirection.opposite()));
	}
	
	/**
	 * 
	 * @param whereAmI
	 * @return It returns the Place at the other side of the street. Returns null if whereAmI does not belong to the street.
	 */
	public Place nextPlace (Place whereAmI){
		if (source.equals(whereAmI))
			return target;
		if (target.equals(whereAmI))
			return source;
		return null;
	}
	
	private Place source;
	private Direction direction;
	private Place target;

}
